import { cloneDeep, } from 'lodash-es';

let userList: UserRecord[] = [
  { userId: 1, userName: '名字', userAge: 5, userSex: '0', userImg: '0', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:44:53', userDescribe: '描述', },
  { userId: 2, userName: '名字', userAge: 2, userSex: '1', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:44:54', userDescribe: '描述', },
  { userId: 3, userName: '名字', userAge: 7, userSex: '0', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:44:55', userDescribe: '描述', },
  { userId: 4, userName: '名字', userAge: 5, userSex: '1', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:44:56', userDescribe: '描述', },
  { userId: 5, userName: '名字', userAge: 2, userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:44:57', userDescribe: '描述', },
  { userId: 6, userName: '名字', userAge: 7, userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:44:58', userDescribe: '描述', },
  { userId: 7, userName: '名字', userAge: 6, userSex: '1', userImg: '1', userInterest: ['1', '1'], userBirthdayTime: '2024-07-13 21:44:59', userDescribe: '描述', },
  { userId: 8, userName: '名字', userAge: 1, userSex: '0', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:45:00', userDescribe: '描述', },
  { userId: 9, userName: '名字', userAge: 7, userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:01', userDescribe: '描述', },
  { userId: 10, userName: '名字', userAge: 7, userSex: '1', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:45:02', userDescribe: '描述', },
  { userId: 11, userName: '名字', userAge: 7, userSex: '1', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:03', userDescribe: '描述', },
  { userId: 12, userName: '名字', userAge: 9, userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:04', userDescribe: '描述', },
  { userId: 13, userName: '名字', userAge: 1, userSex: '0', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:45:05', userDescribe: '描述', },
  { userId: 14, userName: '名字', userAge: 1, userSex: '0', userImg: '0', userInterest: ['1', '1'], userBirthdayTime: '2024-07-13 21:45:06', userDescribe: '描述', },
  { userId: 15, userName: '名字', userAge: 8, userSex: '1', userImg: '0', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:45:07', userDescribe: '描述', },
  { userId: 16, userName: '名字', userAge: 9, userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:45:08', userDescribe: '描述', },
  { userId: 17, userName: '名字', userAge: 6, userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:09', userDescribe: '描述', },
  { userId: 18, userName: '名字', userAge: 6, userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:10', userDescribe: '描述', },
  { userId: 19, userName: '名字', userAge: 6, userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:11', userDescribe: '描述', },
  { userId: 20, userName: '名字', userAge: 3, userSex: '0', userImg: '1', userInterest: ['0', '1'], userBirthdayTime: '2024-07-13 21:45:12', userDescribe: '描述', },
  { userId: 21, userName: '名字', userAge: 3, userSex: '1', userImg: '0', userInterest: ['1', '1'], userBirthdayTime: '2024-07-13 21:45:13', userDescribe: '描述', },
  { userId: 22, userName: '名字', userAge: 4, userSex: '1', userImg: '1', userInterest: ['1', '1'], userBirthdayTime: '2024-07-13 21:45:14', userDescribe: '描述', },
  { userId: 23, userName: '名字', userAge: 4, userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:15', userDescribe: '描述', },
  { userId: 24, userName: '名字', userAge: 8, userSex: '0', userImg: '1', userInterest: ['1', '1'], userBirthdayTime: '2024-07-13 21:45:16', userDescribe: '描述', },
  { userId: 25, userName: '名字', userAge: 2, userSex: '0', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:45:17', userDescribe: '描述', },
  { userId: 26, userName: '名字', userAge: 5, userSex: '0', userImg: '0', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:18', userDescribe: '描述', },
  { userId: 27, userName: '名字', userAge: 4, userSex: '1', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:45:19', userDescribe: '描述', },
  { userId: 28, userName: '名字', userAge: 5, userSex: '0', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:20', userDescribe: '描述', },
  { userId: 29, userName: '名字', userAge: 3, userSex: '1', userImg: '1', userInterest: ['1', '0'], userBirthdayTime: '2024-07-13 21:45:21', userDescribe: '描述', },
  { userId: 30, userName: '名字', userAge: 6, userSex: '0', userImg: '1', userInterest: ['0', '0'], userBirthdayTime: '2024-07-13 21:45:22', userDescribe: '描述', },
];

const mocks: MockRecord[] = [
  {
    method: "get",
    url: "/api/system/user/list",
    response(option) {
      const copyList = cloneDeep(userList);
      
      let resList = userList;
      
      if (option.query.pageNum) {
        resList = copyList.splice((option.query.pageNum - 1) * option.query.pageSize, option.query.pageSize);
      }
      
      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        total: userList.length,
        ...(option.query.pageNum ? { rows: resList } : { data: resList })
      }
      
      return resData;
    }
  },
  {
    method: "get",
    url: "/api/system/user/:userId",
    response(option) {
      const resUser = userList.find(item => item.userId == option.query.userId);

      const resData: responseType = {
        code: resUser ? 200 : 500,
        msg: resUser ? "查询成功" : "查询失败",
        data: resUser,
      }
      
      return resData;
    }
  },
  {
    method: "post",
    url: "/api/system/user",
    response(option) {
      const newUser = option.body;
      
      newUser.userId = userList.length + 1;
      userList.unshift(newUser);
      
      const resData: responseType = {
        code: 200,
        msg: "新增成功",
      }
      
      return resData;
    }
  },
  {
    method: "put",
    url: "/api/system/user",
    response(option) {
      const newUser = option.body;
      
      const index = userList.findIndex(item => item.userId == newUser.userId);
      
      userList.splice(index, 1, newUser);
      
      const resData: responseType = {
        code: 200,
        msg: "修改成功",
      }
      
      return resData;
    }
  },
  {
    method: "delete",
    url: "/api/system/user/:userIds",
    response(option) {
      const userIds = option.query.userIds.split(',');
      
      const filterList = userList.filter(item => !userIds.includes(String(item.userId)));
      
      userList = filterList;
      
      const resData: responseType = {
        code: 200,
        msg: "删除成功",
      }
      return resData;
    }
  }
];

export default mocks;